package com.yunpuvip.sachet.core.aop;

import cn.stylefeng.roses.core.reqres.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
@Order(-2)
public class ServiceExceptionHandler {

    private Logger log = LoggerFactory.getLogger(this.getClass());



    /**
     * 拦截业务异常
     */

    //拦截的异常类型
    @ExceptionHandler(ServiceException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ResponseBody
    public Object bussiness(ServiceException e) {
        System.err.println("error");
        // LogManager.me().executeLog(LogTaskFactory.exceptionLog(ShiroKit.getUser().getId(), e));
        //getRequest().setAttribute("tip", e.getMessage());
        log.error("后台业务异常service:", e);
        return new ErrorResponseData(e.getCode(), e.getMessage());
    }
}
